#ifndef METAITEM_H
#define METAITEM_H


#include "datasuite_global.h"


#include <QObject>
#include <QMetaType>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QStringList>
#include <QPointer>


class MetaData;
class DataSuite;


class DATASUITESHARED_EXPORT MetaItem : public QObject
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:

        Data()
        {
            editable = true;
        }

        Data(const Data& other) : QSharedData(other)
        {
            name = other.name;
            editable = other.editable;
            referencePath = other.referencePath;
            options = other.options;
        }

        QString name;
        bool editable;

        QStringList options;

        QString referencePath;
        QPointer<DataSuite> referenceObject;

    };

    Q_PROPERTY(QString name READ name WRITE setName)
    Q_PROPERTY(bool editable READ editable WRITE setEditable)
    Q_PROPERTY(QStringList options READ options WRITE setOptions)

    Q_PROPERTY(QString referencePath READ referencePath WRITE setReferencePath)


public:

    Q_INVOKABLE MetaItem(MetaData *parent = 0);
    MetaItem(const MetaItem& other);

    QString name() const;
    void setName(const QString& name);

    bool editable() const;
    void setEditable(bool editable);

    QStringList options() const;
    void setOptions(const QStringList& options);

    QString referencePath() const;
    void setReferencePath(const QString& referencePath);

    DataSuite* referenceObject() const;
    void setReferenceObject(DataSuite* referenceObject);

    MetaData* metaData() const;


protected slots:

    void onUpdateParent();
    void onUpdateReference();


private:

    QExplicitlySharedDataPointer<Data> d;


};


Q_DECLARE_METATYPE(MetaItem*)


#endif // METAITEM_H
